package ui.home.column3.notice

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.*
import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.painter.BitmapPainter
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import model.enums.NoticeType
import model.vo.FriendNotificationItem
import model.vo.GroupNotificationItem
import theme.EasyChatTheme
import ui.compose.NetworkImage


/**
 * @author wei kunJie
 * @date 2024/4/14 21:50:28
 */
@Composable
fun GroupNotification(
    easyChatTheme: MutableState<EasyChatTheme>,
    modifier: Modifier,
    items: MutableList<GroupNotificationItem>
) {
    Column(modifier = modifier.background(color = easyChatTheme.value.mainColor2)) {
        Spacer(modifier = Modifier.height(33.dp))
        //标题行
        Row(modifier = Modifier.fillMaxWidth().padding(horizontal = 25.dp)) {
            Text(text = "群通知", modifier = Modifier.weight(1f), fontSize = 18.sp)
            IconButton(modifier = modifier.size(20.dp),
                onClick = {}) {
                Icon(
                    modifier = modifier.fillMaxSize(),
                    painter = painterResource("icon/ic_delete.svg"),
                    contentDescription = "删除全部"
                )
            }
        }
        Spacer(modifier = Modifier.height(25.dp))
        LazyColumn(modifier = Modifier.weight(1f).fillMaxWidth()) {
            items(items) { item ->
                GroupNotificationRow(easyChatTheme, item)
                Spacer(modifier = Modifier.height(15.dp))
            }
        }
    }
}

@Composable
fun GroupNotificationRow(easyChatTheme: MutableState<EasyChatTheme>, item: GroupNotificationItem) {
    Box(
        modifier = Modifier.padding(horizontal = 50.dp).background(
            color = easyChatTheme.value.mainWhite,
            shape = RoundedCornerShape(5.dp)
        )
    ) {
        Row(modifier = Modifier.padding(15.dp)) {
            //头像
            NetworkImage(
                url = item.headImage,
                painterFor = { remember { BitmapPainter(it) } },
                contentDescription = "头像",
                modifier = Modifier.size(50.dp).clip(CircleShape),
                contentScale = ContentScale.Crop,
                defaultPainterFor = painterResource("image/default_head.png")
            )
            Spacer(modifier = Modifier.width(15.dp))
            Column {
                Row {
                    Text(text = item.groupName, fontSize = 14.sp, color = easyChatTheme.value.mainColor)
                    Spacer(modifier = Modifier.width(4.dp))
                    Text(text = item.time, fontSize = 14.sp, color = Color(0XEE696969))
                }
                Spacer(modifier = Modifier.height(10.dp))
                Text(text = item.content, fontSize = 14.sp, color = Color(0XEE696969))
            }
            Spacer(modifier = Modifier.weight(1f))
            if (item.noticeType != NoticeType.groupCreate) {
                Button(
                    onClick = {},
                    colors = ButtonDefaults.buttonColors(
                        backgroundColor = easyChatTheme.value.mainColor,
                    )
                ) {
                    Text(text = "同意", color = Color.White)
                }
                Spacer(modifier = Modifier.width(12.dp))
                Button(
                    onClick = {},
                    colors = ButtonDefaults.buttonColors(
                        backgroundColor = Color(0XFFC75450)
                    )
                ) {
                    Text(text = "拒绝", color = Color.White)
                }
            }
        }
    }
}